Servicenow- Scripting Blog

    • How to access last worknotes?
      • We can use “current.comments.getJournalEntry(1)” to access last worknotes.

    • hasRole()
      • It returns true if the current user has the specified role or the admin role

    • How to get system property?
      • getProperty("PROPERTY_NAME ");

    • How to set system property?
      • setProperty("PROPERTY_NAME ", “property_value”);

    • How to alert Assigned to user name from client script?
      • var p=g_form.getReference(“assigned_to”).name;
      • alert(p);

    • How to access user data from client script
      • g_user.userName
      • g_user.userID
      • g_user.firstName

    • How to access user data from Server Side Script
      • var firstName = gs.getUser().getFirstName();
      • var email = gs.getUser().getEmail();
      • getUser();

    • How to get sys_id from client script
      • alert(g_form.getUniqueValue());

    • How to get current form table display value in client script
      • alert(g_form.getDisplayValue()); and
      • alert(g_form.getDisplayValue(“assigned_to”))

    • How to hide the related list from client script
      • hideRelatedList("REL:SYSIDOFRELATEDLIST");

    • How to hide section from script
      • setSectionDisplay("closure_information", true);

    • How to fire Event from Server-side script
      • eventQueue(“EVENTNAME”, GlideRecord, Parm1, Parm2)

    • How to write GlideRecord on incident to get active records
      • Var gr=New GlideRecord(“incident”);
      • addQuery(“active”,true);
      • query();
      • if(gr.next()){
      • info(gr.number);
      • }

    • G-FORM:GlideForm.js is the Javascript class used to customize forms.
      • getValue(‘short_description’)
      • setValue(‘short_description’, “”)
      • addOption(‘priority’, ‘2.5’, ‘2.5 – Moderately High’, 3)
      • getTableName()
      • addErrorMessage(‘This is an error’)
      • addInfoMessage(‘The top five fields in this form are mandatory’)
      • showFieldMsg(‘impact’,’Low impact response time can be one week’,’info’)
      • showFieldMsg(‘impact’,’Low impact not allowed with High priority’,’error’)
      • flash(“incident.number”, “#FFFACD”, 0)

    • g_user: g_user is a global object in GlideUser, can only used in Client Script contains name and role information about the current user.
      • userName
      • userID
      • firstName
      • getClientData(“loginlanguage”)
      • hasRole(‘admin’)
      • hasRoleExactly(‘util’)
      • hasRoleFromList(“itil, maint”)
      • hasRoles()